from sqlalchemy import Integer, String, Numeric, DateTime, Column, ForeignKey

from database import db
from .account import Account
from .order import Order


class AccountHistory(db.Model):
    CREDIT_DIRECTION = 'credit'
    DEBIT_DIRECTION = 'debit'
    id = Column(Integer, primary_key=True)
    direction = Column(String(10), default='debit', doc='借贷方向 debit 借方  credit  贷方')
    amount = Column(Numeric(precision=15, scale=4), doc='合计')
    remark = Column(String(200), doc='描述信息')
    type = Column(String(20), doc='账户历史类型')
    settle_time = Column(DateTime, doc='交易时间')
    created_at = Column(DateTime, doc='创建日间')
    update_at = Column(DateTime, doc='更新时间')
    status = Column(String(20), default='done')
    order_id = Column(ForeignKey(Order.id), doc='订单id')
    account_id = Column(ForeignKey(Account.id), doc='帐户id', nullable=False)
